package com.swyc.osschat.Test.cydmx;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;

/**
 * @description 除妖大冒险用于计算仙玉存款的方法
 * @Author: z156940l@outlook.com
 * @className Test
 * @Date: 2023/3/14 15:14
 */
public class Test {

    public static String[] weekDays = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
    // 初始值
    public static int storage = 105000;
    public static int noStorage = 1085;
    public static int security = 345;
    // 每天随机数和每周随机数
    public static int dayRandom = 500;
    public static int weekRandom = 2000;
    // 周末活动固定收入
    public static int weekRegular = 1250;
    // 周一额外收入80
    public static int monday = 80;

    public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");

    public static void main(String[] args) {
        // 今天的日期
        Calendar now = Calendar.getInstance();
        now.setTime(new Date());

        Random random = new Random();
        // 循环一年
        for (int i = 0; i < 365; i++) {
            // 加上每天的保底收入
            noStorage += security;
            Integer week = getWeek(now);
            // 周一额外收入80
            if (week == 1){
                noStorage += monday;
            }
            // 周日活动收入1250
            if (week == 0){
                noStorage += weekRegular;
            }
            // 每天领取六次利息
            int insert = 0;
            for (int j = 0; j < 6; j++) {
                int curInterest = getCurInterest();
                noStorage += curInterest;
                insert = curInterest;
                deposit();
            }
            now.add(Calendar.DAY_OF_MONTH, 1);
            String date = sdf.format(now.getTime());
            int dayRandomAmt = random.nextInt(dayRandom);
            noStorage += dayRandomAmt;
            // 存款
            deposit();
            int weekRandomAmt = 0;
            if (week == 0){
                weekRandomAmt = random.nextInt(weekRandom);
                noStorage += weekRandomAmt;
                dayRandomAmt += weekRandomAmt;
                // 存款
                deposit();
                System.out.println("今天是：" + date + weekDays[week] + "，今天随机收入：[" + dayRandomAmt + "]，当前存款：[" + storage + "],当前账户外余额：[" + noStorage + "]，当前每次利息：[" + insert + "]。");
            }else {
                System.out.println("今天是：" + date + weekDays[week] + "，今天随机收入：[" + dayRandomAmt + "]，当前存款：[" + storage + "],当前账户外余额：[" + noStorage + "]，当前每次利息：[" + insert + "]。");
            }
        }
    }

    /**
     * 获取周几
     * @param calendar
     * @return
     */
    public static Integer getWeek(Calendar calendar){
        int w = calendar.get(Calendar.DAY_OF_WEEK) - 1;
        if (w < 0)
            w = 0;
        return w;
    }

    // 存款
    public static void deposit(){
        while (true){
            if (noStorage >= 5000){
                noStorage -= 5000;
                storage += 5000;
            }else {
                break;
            }
        }
    }

    public static int getCurInterest(){
        return storage / 5000 * 15;
    }
}
